﻿using FastReport;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using static WinFormsApp1.SuYi.ReportsShow.WhiteporkReports;

namespace WinFormsApp1.SuYi.ReportsShow
{
    public partial class WhiteporkCollect : Form
    {
        public WhiteporkCollect()
        {
            InitializeComponent();
        }
        public string frx;
        private void WhiteporkCollect_Load(object sender, EventArgs e)
        {
            Report report = new Report();
            if (!string.IsNullOrWhiteSpace(frx))
                report.Load(frx);




            //var item = await HttpClientHelper.RequestUrl<object, ApiResultFY2<List<CheckInDeailDto>>>("http://localhost:5106/api/Reports/", "QueryCheckDetail", HttpClientHelper.MethodType.POST, check);


            string url = URLCommon.Url2+@"/Reports/QueryWhiteporkCollect";
            HttpClient client = new HttpClient();
            WhiteporkDto whitepork = new WhiteporkDto();
            var content = new StringContent(JsonSerializer.Serialize<WhiteporkDto>(whitepork));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var results = info["data"].Value<JArray>();
            //var results = info["data"].Value<JToken>();
            //var resultss = results["list"].Value<JArray>();

            //// 加载报表模板，这里假设模板文件是 "YourReportTemplate.frx"
            report.Load(@"../../../Reports\白条称重汇总\333.frx");

            DataSet ds = new DataSet();
            DataTable fr_dt = new DataTable();
            fr_dt.TableName = "baseInfos";
            fr_dt.Columns.Add("patName", typeof(String));//*****列名设置需要与标签模板一致*****
            fr_dt.Columns.Add("patset", typeof(String));
            fr_dt.Columns.Add("patone", typeof(String));
            fr_dt.Columns.Add("pattwo", typeof(String));
            fr_dt.Columns.Add("patthree", typeof(String));

            for (int i = 0; i < results.Count; i++)
            {
                fr_dt.Rows.Add(results[i]["goodsMinute"], results[i]["slaughterNo"], results[i]["skinWeight"], results[i]["grossWeight"], results[i]["netWeight"]);

            }
            ds.Tables.Add(fr_dt);
            report.RegisterData(ds);//将数据传递至标签模板

            //report.Print();//打印标签
            designerControl1.Report = report;
            //restore the design layout. Without this code, the designer tool windows will be unavailable
            designerControl1.RefreshLayout();
        }
        public void FastProt()
        {

            Report report = new Report();



        }

        /// <summary>
        /// 白条称重明细
        /// </summary>
        public class WhiteporkDto
        {
           
            /// <summary>
            /// 屠宰编号
            /// </summary>
            public string SlaughterNo { get; set; }
            /// <summary>
            /// 商品代号
            /// </summary>
            public string GoodsMinute { get; set; }
            /// <summary>
            /// 称重时间
            /// </summary>
            public DateTime WhiteWeighingDate { get; set; }
            /// <summary>
            /// 皮重
            /// </summary>
            public double SkinWeight { get; set; }
            /// <summary>
            /// 毛重
            /// </summary>
            public double GrossWeight { get; set; }
            /// <summary>
            /// 净重
            /// </summary>
            public double NetWeight { get; set; }
          
            /// <summary>
            /// 数量
            /// </summary>
            public int WeighingNum { get; set; }
        }
    }
}
